'''
题：下面是一个计算斐波那契数列的生成器(使用迭代器来生成)：
'''
#方法1：
# def fibon(n):
#     a = b = 1
#     for i in range(n):
#         yield a
#         a, b = b, a + b
# for x in fibon(10):
#     print(x)

#方法二：使用迭代器来实现斐波那契数列
class Fib:

    def __init__(self):
        self.after = 1
        self.front = 0

    def __iter__(self):
        return self

    def __next__(self):
        value = self.front
        self.front ,self.after= self.after ,self.front+self.after
        return value
teiter = Fib()
for i in range(10):
    print(next(iter(teiter)))